from flask import Flask,request
import json
from returnJsonResult import applog_json
from checkLog import checkApp
#render_template, redirect, url_for, send_from_directory
from os import path
# -*- coding:utf-8  -*-
__author__ = 'wangd'

app = Flask(__name__)
#当前文件的完整路径
now_base_path = path.abspath(path.dirname(__file__))
# print(now_base_path)

@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route("/app_log_upload_debug", methods=["GET", "POST"])
def app_log_upload_debug():
    ip = request.remote_addr
    if request.method=='POST':
        reportContent = request.get_data(as_text=True)#得到上报的内容
        content=reportContent[0:reportContent.rfind('&checksum')]
        logContent=content[content.find('='):][1:]
        checkApp(ip,logContent)
    else:
        pass
    return json.dumps(applog_json)

if __name__ == '__main__':
    app.run(host='127.0.0.1',port=8001,debug=True)

